import axiosInstance from './index'
// import {id} from "element-plus/es/locale/index";

const axios = axiosInstance

//login & regist
export const check_user = (username, password, role) => {
    return axios.post(`http://localhost:8000/api/user/login_check/`,{'username':username, 'password':password, 'role':role})
}

export const postUser = (username, password) => {
    return axios.post(`http://localhost:8000/api/user/`,{'name':username, 'pwd':password, 'role':'user'})
}

export const checkName = (username) => {
    return axios.post(`http://localhost:8000/api/user/check_name/`,{'username':username})
}

//user
export const getUser = (username) => {
    return axios.get(`http://localhost:8000/api/user/`)
}

export const deleteUser = (id) => {
    return axios.delete(`http://localhost:8000/api/user/${id}/`)
}

export const updateUser = (id, newData) => {
    return axios.put(`http://localhost:8000/api/user/${id}/`, newData)
}

export const findByUserTitle = (name_pattern) => {
    return axios.get(`http://localhost:8000/api/user/search_by_name_pattern/`, {
        params: { name_pattern }
    })
}

export const findByUserType = (role) => {
    return axios.get(`http://localhost:8000/api/user/search_by_role/`, {
        params: { role }
    })
}
//Drug
export const getDrugs = ()=>{
    return axios.get(`http://localhost:8000/api/drug/`)
}

export const deleteDrug = (id) =>{
    return axios.delete(`http://localhost:8000/api/drug/${id}/`)
}

export const updateDrug = (id, newData) => {
    return axios.put(`http://localhost:8000/api/drug/${id}/`, newData)
}

export const postDrug = (drug_name,drug_inprice,drug_outprice,drug_type) => {
    return axios.post(`http://localhost:8000/api/drug/`,{"drug_name":drug_name,"drug_inprice":drug_inprice,
        "drug_outprice":drug_outprice,"drug_type":drug_type})
}

export const findByDrugTitle = (title_pattern) => {
    return axios.get(`http://localhost:8000/api/drug/search_by_title_pattern/`, {
        params: { title_pattern }
    })
}

export const findByDrugType = (type) => {
    return axios.get(`http://localhost:8000/api/drug/search_by_type/`, {
        params: { type }
    })
}


//buyer
export const getBuyer = ()=>{
    return axios.get(`http://localhost:8000/api/buyer/`)
}

export const deleteBuyer = (id) =>{
    return axios.delete(`http://localhost:8000/api/buyer/${id}/`)
}

export const updateBuyer = (id, newData) => {
    return axios.put(`http://localhost:8000/api/buyer/${id}/`, newData)
}

export const postBuyer = (name,gender,phone) => {
    return axios.post(`http://localhost:8000/api/buyer/`,{"name":name,"gender":gender,"phone":phone})
}


//manufacturer
export const getManufacturer = ()=>{
    return axios.get(`http://localhost:8000/api/manufacture/`)
}

export const deleteManufacturer = (id) =>{
    return axios.delete(`http://localhost:8000/api/manufacture/${id}/`)
}

export const updateManufacturer = (id, newData) => {
    return axios.put(`http://localhost:8000/api/manufacture/${id}/`, newData)
}

export const postManufacturer = (name,phone,address) => {
    return axios.post(`http://localhost:8000/api/manufacture/`,{"name":name,"phone":phone,"address":address})
}

//stock
export const getStock = ()=>{
    return axios.get(`http://localhost:8000/api/stock/`)
}

export const deleteStock = (id) =>{
    return axios.delete(`http://localhost:8000/api/stock/${id}/`)
}

export const updateStock = (id, newData) => {
    return axios.put(`http://localhost:8000/api/stock/${id}/`, newData)
}

export const postStock = (stock_quantity, address, drug_name, stock_warning) => {
    return axios.post(`http://localhost:8000/api/stock/`,{'stock_quantity':stock_quantity, 'address':address, 'drug_name':drug_name, 'stock_warning':stock_warning})
}

export const findByStockTitle = (name) => {
    return axios.get(`http://localhost:8000/api/stock/search_by_name_pattern/`, {
        params: { name }
    })
}

export const findByStockType = (type) => {
    return axios.get(`http://localhost:8000/api/stock/search_by_type/`, {
        params: { type }
    })
}
//sale
export const getSale = ()=>{
    return axios.get(`http://localhost:8000/api/sale/`)
}

export const deleteSale = (id) =>{
    return axios.delete(`http://localhost:8000/api/sale/${id}/`)
}

export const updateSale = (id, newData) => {
    return axios.put(`http://localhost:8000/api/sale/${id}/`, newData)
}

export const postSale = (drug_name, sale_date, sale_discount, quantity, total_amount, buyer) => {
    return axios.post(`http://localhost:8000/api/sale/`,{'drug_name':drug_name, 'sale_date':sale_date,
        'sale_discount':sale_discount, 'quantity':quantity, 'total_amount':total_amount, 'buyer':buyer})
}
//supply
export const getSupply = ()=>{
    return axios.get(`http://localhost:8000/api/supply/`)
}

export const deleteSupply = (id) =>{
    return axios.delete(`http://localhost:8000/api/supply/${id}/`)
}

export const updateSupply = (id, newData) => {
    return axios.put(`http://localhost:8000/api/supply/${id}/`, newData)
}

export const postSupply = (drug_name, manufacturer_name, supply_date, quantity, total_amount) => {
    return axios.post(`http://localhost:8000/api/supply/`,{'drug_name':drug_name, 'manufacturer_name':manufacturer_name, 'supply_date':supply_date, 'quantity':quantity, 'total_amount':total_amount})
}
//treat
export const getTreat = ()=>{
    return axios.get(`http://localhost:8000/api/treat/`)
}

export const deleteTreat = (id) =>{
    return axios.delete(`http://localhost:8000/api/treat/${id}/`)
}

export const updateTreat = (id, newData) => {
    return axios.put(`http://localhost:8000/api/treat/${id}/`, newData)
}

export const postTreat = (drug_name, drug_quantity, treatment_date, treatment_method, treatment_reseon, treated_by) => {
    return axios.post(`http://localhost:8000/api/treat/`,{'drug_name':drug_name, 'drug_quantity':drug_quantity, 'treatment_date':treatment_date,
        'treatment_method':treatment_method, 'treatment_reseon':treatment_reseon,'treated_by':treated_by})
}

export const findByPeople = (name) => {
    return axios.get(`http://localhost:8000/api/treat/search_by_name/`, {
        params: { name }
    })
}

export const findByDate = (date) => {
    return axios.get(`http://localhost:8000/api/treat/search_by_date/`, {
        params: { date }
    })
}